package com.google.coffeeshop.gui.desktop.orderpayment;

import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.SwingConstants;

import vn.bang.utility.ImageUtil;

import com.google.coffeeshop.entity.ProductDTO;

public class ItemButton extends JButton {
	private static final long serialVersionUID = 1L;
	
	private ProductDTO product;
	
	public ItemButton(ProductDTO product, URL url) throws IOException {
		this.product = product;
		BufferedImage imageBuff = ImageIO.read(url);
		Image image = ImageUtil.fit(imageBuff, new Dimension(200, 200), this);
		setIcon(new ImageIcon(image));
		setText(product.getName());
		setSize(100, 100);
		setLayout(new CardLayout(0, 0));
		setVerticalTextPosition(SwingConstants.BOTTOM);
	    setHorizontalTextPosition(SwingConstants.CENTER);
	}
	
	public ProductDTO getProduct() {
		return product;
	}
	
}
